import os
import sys
import time


from fastapi import FastAPI
from fastapi import  requests , responses
#from fastapi_offline import FastAPIOffline
import uvicorn

from ter import  iotTer
import busModbusRtu
import bus645
import busCalculateWx
import bus104ly
print('start iot server.')

app = FastAPI()
@app.get("/")
async def appRoot():
    return {
        'start app zongneng iot server 2025'
    }

if __name__=="__main__":
    iotTer.apiUrl = "https://iot.zn-power.com/zweb/api/znapi"
    iotTer.terCode = "terLy"
    if len(sys.argv)>1:
        iotTer.terCode = sys.argv[1]

    print(f'---------  start iot server [{iotTer.terCode}] --------------')
    iotTer.loadTerData()
    print('loaded')
    iotTer.startBuses()
    print('started')


    print(iotTer.terData['terInfo'])

    uvicorn.run(
        "iotserver:app" ,
        host="0.0.0.0",
        port=12002 ,
        #reload= True
    )